#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>


int main() {
    umask(0);
    int fd = open("log.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    if(fd == -1) {
        perror("open fail");
        return 1;
    }
    int ret = dup2(fd, stdout->_fileno);
    if(-1 == ret) {
        perror("dup fail");
        return 1;
    }
    printf("fd = %d ret = %d\n",fd, ret);
    close(fd);
    return 0;
}
